import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:oktoast/oktoast.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:super_person_app/constants/colors.dart';
import 'package:super_person_app/routes/app_pages.dart';
import 'package:super_person_app/routes/app_routes.dart';

import 'app_binding.dart';
import 'app_logic.dart';

class AppPage extends GetView<AppLogic> {
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 667),
      builder: () => GestureDetector(
        onTap: () {
          FocusScopeNode currentFocus = FocusScope.of(context);
          if (!currentFocus.hasPrimaryFocus &&
              currentFocus.focusedChild != null) {
            FocusManager.instance.primaryFocus!.unfocus();
          }
        },
        child: OKToast(
            child: RefreshConfiguration(
          headerBuilder: () => const WaterDropHeader(),
          footerBuilder: () => const ClassicFooter(),
          enableScrollWhenRefreshCompleted: true,
          //这个属性不兼容PageView和TabBarView,如果你特别需要TabBarView左右滑动,你需要把它设置为true
          enableLoadingWhenFailed: true,
          //在加载失败的状态下,用户仍然可以通过手势上拉来触发加载更多
          hideFooterWhenNotFull: true,
          // Viewport不满一屏时,禁用上拉加载更多功能
          enableBallisticLoad: false,
          // 可以通过惯性滑动触发加载更多
          child: GetMaterialApp(
            debugShowCheckedModeBanner: false,
            enableLog: true,
            initialRoute: Routes.app,
            getPages: AppPages.routes,
            defaultTransition: Transition.cupertino,
            initialBinding: AppBinding(),
            unknownRoute: AppPages.unknownRoute,
            theme: ThemeData(
                colorScheme:  Theme.of(context).colorScheme.copyWith(secondary:  BasicColor.mainColor.withOpacity(0.3)),
                hoverColor: BasicColor.mainColor.withOpacity(0.3),
                hintColor: BasicColor.mainColor.withOpacity(0.3),
                primaryColor: BasicColor.mainColor,
                fontFamily: "PingFang",
                highlightColor: const Color.fromRGBO(255, 255, 255, .05),
                splashColor: BasicColor.mainColor.withOpacity(0.3)),
            builder: EasyLoading.init(),
            localizationsDelegates: const [
              RefreshLocalizations.delegate,
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],
            supportedLocales: const [
              Locale('en'),
            ],
          ),
        )),
      ),
    );
  }
}
